package com.music.controller;

import com.music.pojo.UserInfo;
import com.music.service.CommentService;
import com.music.service.UserService;
import com.music.utils.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @RequestMapping("countByMid")
    public ResultInfo countByMid(Integer mid){
        Long num = commentService.countByMid(mid);
        ResultInfo resultInfo = new ResultInfo(true);
        resultInfo.setData(num);
        return resultInfo;
    }

    @RequestMapping("addComment")
    public ResultInfo addComment(Integer mid, Integer cid, String commentText, HttpSession session){
        ResultInfo resultInfo = new ResultInfo();
        UserInfo userInfo = (UserInfo) session.getAttribute("userInfo");
        commentService.addComment(mid,cid,userInfo.getUid(),commentText);
        return resultInfo;
    }
}
